package com.xiaxinyu.redis.client.core;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author XIAXINYU3
 * @date 2021/6/7
 */
@Configuration
public class ThreadPoolConfig {
    private static final String MIGRATION_SERVICE_EXECUTOR = "redisThreadPool";

    /**
     * 用于数据迁移执行器
     *
     * @return 线程池
     */
    @Bean(name = MIGRATION_SERVICE_EXECUTOR)
    public AsyncTaskExecutor asyncMigrationServiceExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setThreadNamePrefix(MIGRATION_SERVICE_EXECUTOR);
        //后续可根据实际业务或者CPU核数进行设置
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(20);
        executor.setQueueCapacity(10);
        return executor;
    }
}
